# 消息处理模块
import json

class ReplyHandler:
    def __init__(self, message):
        self.message = message
        self.inputs = message.get("inputs", {})
        self.query = message.get("query")
        self.response_mode = message.get("response_mode")
        self.conversation_id = message.get("conversation_id")
        self.user = message.get("user")
        self.files = message.get("files", [])

    def process_message(self):
        """
        处理消息并返回处理结果。
        """
        if self.query:
            return self._process_query()
        else:
            return "消息中未找到 'query' 字段"

    def _process_query(self):
        """
        处理查询事件。
        """
        query = self.query.strip()
        if "天气" in query:
            return f"您询问的是关于天气的信息，请提供具体的位置或日期。"
        else:
            return f"您询问的内容是：{query}"

    def __str__(self):
        """
        返回消息的字符串表示。
        """
        return json.dumps(self.message, ensure_ascii=False, indent=4)

# # 示例消息
# example_message = {
#     "inputs": {},
#     "query": "的天气",
#     "response_mode": "blocking",
#     "conversation_id": "480bfe43-be60-4942-87fa-d3e69c4fb948",
#     "user": "abc-123",
#     "files": [
#         {
#             "type": "image",
#             "transfer_method": "remote_url",
#             "url": "https://cloud.dify.ai/logo/logo-site.png"
#         }
#     ]
# }
#
# # 创建 ReplyHandler 实例并处理消息
# handler = ReplyHandler(example_message)
# processed_message = handler.process_message()
#
# print(processed_message)
